import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class LeftistTree {

    static int MAXN = 100001;
    static int n;
    static int[] nums = new int[MAXN];
    static int[] left = new int[MAXN];
    static int[] right = new int[MAXN];
    static int[] dist = new int[MAXN];
    static int[] father = new int[MAXN];

    static int find(int x) {
        return father[x] = x == father[x] ? x : find(father[x]);
    }

    static void init() {
        dist[0] = -1;
        for (int i = 1; i <= n; i++) {
            left[i] = right[i] = dist[i] = 0;
            father[i] = i;
        }
    }

    static int merge(int rootA, int rootB) {
        if (rootA == 0 || rootB == 0) {
            return rootA + rootB;
        }
        if (nums[rootA] > nums[rootB] || (nums[rootA] == nums[rootB] && rootA > rootB)) {
            int temp = rootA;
            rootA = rootB;
            rootB = temp;
        }
        right[rootA] = merge(right[rootA], rootB);
        if (dist[left[rootA]] < dist[right[rootA]]) {
            int temp = left[rootA];
            left[rootA] = right[rootA];
            right[rootA] = temp;
        }
        dist[rootA] = dist[right[rootA]] + 1;
        father[left[rootA]] = father[right[rootA]] = rootA;
        return rootA;
    }

    static int pop(int root) {
        father[left[root]] = left[root];
        father[right[root]] = right[root];

        father[root] = merge(left[root], right[root]);
        left[root] = right[root] = dist[root] = 0;
        return father[root];
    }

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        n = (int) in.nval;
        in.nextToken();
        int m = (int) in.nval;
        init();
        for (int i = 1; i <= n; i++) {
            in.nextToken();
            nums[i] = (int) in.nval;
        }
        for (int i = 0, op, x, y; i < m; i++) {
            in.nextToken();
            op = (int) in.nval;
            if (op == 1) {
                in.nextToken();
                x = (int) in.nval;
                in.nextToken();
                y = (int) in.nval;
                if (nums[x] != -1 && nums[y] != -1) {
                    int l = find(x);
                    int r = find(y);
                    if (l != r) {
                        merge(l, r);
                    }
                }
            } else {
                in.nextToken();
                x = (int) in.nval;
                if (nums[x] == -1) {
                    out.println(-1);
                } else {
                    int ans = find(x);
                    out.println(nums[ans]);
                    pop(ans);
                    nums[ans] = -1;
                }
            }

        }
        out.flush();
        out.close();
        br.close();
    }

}